#include <stdio.h>

#define MAX_ROW (0x8000000) /* =max_len/16 */
#define BSP_HEXDUMP2_PRINT_WITH 4

void bsp_hexdump(FILE *stream, const void *src, unsigned long start_addr, size_t len, size_t width)
{
	unsigned int c, i, rows;
	const unsigned int *row_pos = NULL;
	const unsigned int *data = NULL;

	if (width == 0)
		return;

	data = src;
	rows = (len % width) == 0 ? len / width : len / width + 1;

	if (rows > MAX_ROW) {
		printf("error:Input param(len) is greater than 2GB!\n");
		return;
	}

	for (i = 0; i < rows; i++) {
		row_pos = data;
		(void)fprintf(stream, "%08lx: ", i * 0x10 + start_addr);
		do {
			c = *data++;
			(void)fprintf(stream, " %08x", c);
		} while (((data - row_pos) % BSP_HEXDUMP2_PRINT_WITH) != 0);
		(void)fprintf(stream, "\n");
	}
	(void)fflush(stream);
}
